﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VirtualOrg.Mobile.DBAccess;
using VirtualOrg.Mobile.Models;

namespace VirtualOrg.Mobile.Process
{
    public static class VOrgProcess
    {
        public static List<SelectListItem> GetCategoryList()
        {
            List<SelectListItem> categoryList = new List<SelectListItem>();
            using (VOrgStoreDataContext datacontext = new VOrgStoreDataContext())
            {
                var result = datacontext.CategoryMasters.Where(obj => (obj.CategoryType == "ORG"));
                categoryList.Add(new SelectListItem());
                foreach (var item in result)
                {
                    categoryList.Add(new SelectListItem() { Text = item.Title, Value = item.CategoryID.ToString() });
                }
            }

            return categoryList;
        }

        public static List<SelectListItem> GetSubCategoryList(long categoryId)
        {
            List<SelectListItem> subcategoryList = new List<SelectListItem>();
            using (VOrgStoreDataContext datacontext = new VOrgStoreDataContext())
            {
                var result = datacontext.SubCategoryMasters.Where(obj => (obj.CategoryID == categoryId));
                subcategoryList.Add(new SelectListItem() { Text = "", Value = "" });
                foreach (var item in result)
                {
                    subcategoryList.Add(new SelectListItem() { Text = item.Title, Value = item.SubCategoryID.ToString() });
                }
            }

            return subcategoryList;
        }

        public static IEnumerable<OrgModel> GetOrgList(long userId)
        {
            List<OrgModel> orgList = new List<OrgModel>();
            using (VOrgStoreDataContext datacontext = new VOrgStoreDataContext())
            {
                var result = datacontext.Organizations.Where(obj => (obj.Owner == userId));
                foreach (var item in result)
                {
                    orgList.Add(new OrgModel()
                    {
                        Description = item.Description,
                        OrgID = item.OrganizationID,
                        Tagline = item.Tagline,
                        Title = item.Title
                    });
                }
            }

            return orgList.AsEnumerable();
        }
    }
}